﻿
namespace Indeco.G24.Windows.Forms
{
	/// <summary>
	/// abstract CauHinhHeThong typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class CauHinhHeThongDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<CauHinhHeThongDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.CauHinhHeThong _currentCauHinhHeThong = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxCauHinhHeThongDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxCauHinhHeThongErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxCauHinhHeThongBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IDCauHinhHeThong property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDCauHinhHeThongDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Ten property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxTenDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the GiaTri property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxGiaTriDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the MoTa property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxMoTaDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.CauHinhHeThong> _CauHinhHeThongList;
				
		/// <summary> 
		/// The list of CauHinhHeThong to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.CauHinhHeThong> CauHinhHeThongList
		{
			get {return this._CauHinhHeThongList;}
			set
			{
				this._CauHinhHeThongList = value;
				this.uxCauHinhHeThongBindingSource.DataSource = null;
				this.uxCauHinhHeThongBindingSource.DataSource = value;
				this.uxCauHinhHeThongDataGridView.DataSource = null;
				this.uxCauHinhHeThongDataGridView.DataSource = this.uxCauHinhHeThongBindingSource;				
				//this.uxCauHinhHeThongBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxCauHinhHeThongBindingSource_ListChanged);
				this.uxCauHinhHeThongBindingSource.CurrentItemChanged += new System.EventHandler(OnCauHinhHeThongBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnCauHinhHeThongBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentCauHinhHeThong = uxCauHinhHeThongBindingSource.Current as Entities.CauHinhHeThong;
			
			if (_currentCauHinhHeThong != null)
			{
				_currentCauHinhHeThong.Validate();
			}
			//_CauHinhHeThong.Validate();
			OnCurrentEntityChanged();
		}

		//void uxCauHinhHeThongBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.CauHinhHeThong"/> instance.
		/// </summary>
		public Entities.CauHinhHeThong SelectedCauHinhHeThong
		{
			get {return this._currentCauHinhHeThong;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxCauHinhHeThongDataGridView.VirtualMode;}
			set
			{
				this.uxCauHinhHeThongDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxCauHinhHeThongDataGridView.AllowUserToAddRows;}
			set {this.uxCauHinhHeThongDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxCauHinhHeThongDataGridView.AllowUserToDeleteRows;}
			set {this.uxCauHinhHeThongDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxCauHinhHeThongDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxCauHinhHeThongDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="CauHinhHeThongDataGridViewBase"/> class.
		/// </summary>
		public CauHinhHeThongDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxCauHinhHeThongDataGridView = new System.Windows.Forms.DataGridView();
			this.uxCauHinhHeThongBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxCauHinhHeThongErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDCauHinhHeThongDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxTenDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxGiaTriDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxMoTaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxCauHinhHeThongDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxCauHinhHeThongBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxCauHinhHeThongErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxCauHinhHeThongErrorProvider
			// 
			this.uxCauHinhHeThongErrorProvider.ContainerControl = this;
			this.uxCauHinhHeThongErrorProvider.DataSource = this.uxCauHinhHeThongBindingSource;						
			// 
			// uxCauHinhHeThongDataGridView
			// 
			this.uxCauHinhHeThongDataGridView.AutoGenerateColumns = false;
			this.uxCauHinhHeThongDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxCauHinhHeThongDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDCauHinhHeThongDataGridViewColumn,
		this.uxTenDataGridViewColumn,
		this.uxGiaTriDataGridViewColumn,
		this.uxMoTaDataGridViewColumn			});
			this.uxCauHinhHeThongDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxCauHinhHeThongDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxCauHinhHeThongDataGridView.Name = "uxCauHinhHeThongDataGridView";
			this.uxCauHinhHeThongDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxCauHinhHeThongDataGridView.TabIndex = 0;	
			this.uxCauHinhHeThongDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxCauHinhHeThongDataGridView.EnableHeadersVisualStyles = false;
			this.uxCauHinhHeThongDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnCauHinhHeThongDataGridViewDataError);
			this.uxCauHinhHeThongDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnCauHinhHeThongDataGridViewCellValueNeeded);
			this.uxCauHinhHeThongDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnCauHinhHeThongDataGridViewCellValuePushed);
			
			//
			// uxIDCauHinhHeThongDataGridViewColumn
			//
			this.uxIDCauHinhHeThongDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDCauHinhHeThongDataGridViewColumn.DataPropertyName = "IDCauHinhHeThong";
			this.uxIDCauHinhHeThongDataGridViewColumn.HeaderText = "IDCauHinhHeThong";
			this.uxIDCauHinhHeThongDataGridViewColumn.Name = "uxIDCauHinhHeThongDataGridViewColumn";
			this.uxIDCauHinhHeThongDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDCauHinhHeThongDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDCauHinhHeThongDataGridViewColumn.ReadOnly = false;		
			//
			// uxTenDataGridViewColumn
			//
			this.uxTenDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTenDataGridViewColumn.DataPropertyName = "Ten";
			this.uxTenDataGridViewColumn.HeaderText = "Ten";
			this.uxTenDataGridViewColumn.Name = "uxTenDataGridViewColumn";
			this.uxTenDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTenDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTenDataGridViewColumn.ReadOnly = false;		
			//
			// uxGiaTriDataGridViewColumn
			//
			this.uxGiaTriDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxGiaTriDataGridViewColumn.DataPropertyName = "GiaTri";
			this.uxGiaTriDataGridViewColumn.HeaderText = "GiaTri";
			this.uxGiaTriDataGridViewColumn.Name = "uxGiaTriDataGridViewColumn";
			this.uxGiaTriDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxGiaTriDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxGiaTriDataGridViewColumn.ReadOnly = false;		
			//
			// uxMoTaDataGridViewColumn
			//
			this.uxMoTaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxMoTaDataGridViewColumn.DataPropertyName = "MoTa";
			this.uxMoTaDataGridViewColumn.HeaderText = "MoTa";
			this.uxMoTaDataGridViewColumn.Name = "uxMoTaDataGridViewColumn";
			this.uxMoTaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxMoTaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxMoTaDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxCauHinhHeThongDataGridView);
			this.Name = "CauHinhHeThongDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxCauHinhHeThongErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxCauHinhHeThongDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxCauHinhHeThongBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				CauHinhHeThongDataGridViewEventArgs args = new CauHinhHeThongDataGridViewEventArgs();
				args.CauHinhHeThong = _currentCauHinhHeThong;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class CauHinhHeThongDataGridViewEventArgs : System.EventArgs
		{
			private Entities.CauHinhHeThong	_CauHinhHeThong;
	
			/// <summary>
			/// the  Entities.CauHinhHeThong instance.
			/// </summary>
			public Entities.CauHinhHeThong CauHinhHeThong
			{
				get { return _CauHinhHeThong; }
				set { _CauHinhHeThong = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxCauHinhHeThongDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnCauHinhHeThongDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxCauHinhHeThongDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnCauHinhHeThongDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxCauHinhHeThongDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDCauHinhHeThongDataGridViewColumn":
						e.Value = CauHinhHeThongList[e.RowIndex].IDCauHinhHeThong;
						break;
					case "uxTenDataGridViewColumn":
						e.Value = CauHinhHeThongList[e.RowIndex].Ten;
						break;
					case "uxGiaTriDataGridViewColumn":
						e.Value = CauHinhHeThongList[e.RowIndex].GiaTri;
						break;
					case "uxMoTaDataGridViewColumn":
						e.Value = CauHinhHeThongList[e.RowIndex].MoTa;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxCauHinhHeThongDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnCauHinhHeThongDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxCauHinhHeThongDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDCauHinhHeThongDataGridViewColumn":
						CauHinhHeThongList[e.RowIndex].IDCauHinhHeThong = (System.Guid)e.Value;
						break;
					case "uxTenDataGridViewColumn":
						CauHinhHeThongList[e.RowIndex].Ten = (System.String)e.Value;
						break;
					case "uxGiaTriDataGridViewColumn":
						CauHinhHeThongList[e.RowIndex].GiaTri = (System.String)e.Value;
						break;
					case "uxMoTaDataGridViewColumn":
						CauHinhHeThongList[e.RowIndex].MoTa = (System.String)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
